package com.speily.example.service.impl.sys;

import com.speily.example.common.utils.DateUtils;
import com.speily.example.mapper.SnMapper;
import com.speily.example.service.SnService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


/**
 * 生成唯一单号表 接口实现类
 */
@Service
public class SnServiceImpl implements SnService {

    @Resource
    private SnMapper snMapper;

    public String getSnNumber(String type) {
        String date = DateUtils.parseDateToStr( "yyyyMMdd",DateUtils.getNowDate());
        Map<String,String> map = new HashMap<>(16);
        map.put("addTime", date);
        map.put("type", type);
        return date + StringUtils.leftPad(snMapper.getSn(map).toString(), 6, '0');
    }

    @Override
    public String getSn(SN sn) {
        return sn.prefix + getSnNumber(sn.type);
    }
}
